import useScanStore from '@/store/modules/scanMonitor'
import { cloneDeep } from 'lodash'

const { spectrum } = useScanStore()
export const chartConfig = {
  chart: {
    backgroundColor: '#020e1f',
    polar: true,
    type: 'line',
    height: 400,
    spacingTop: 30,
    spacingBottom: 0,
    spacingLeft: 0,
    spacingRight: 20,
    zoomType: 'xy',
    events: {
      redraw(ev) {
        this.specturmMarkers &&
          this.specturmMarkers.forEach(marker => {
            marker.update()
          })
        this.topMarker && this.topMarker.update()
      },
      selection(ev) {
        if (ev.resetSelection) {
          this.update({ xAxis: chartConfig.xAxis })
          return true
        }
        const xAxis = ev.xAxis[0]
        const min = Math.floor(xAxis.min)
        const max = Math.ceil(xAxis.max)
        const xAxisConfig = cloneDeep(chartConfig.xAxis)
        xAxisConfig.max = max
        xAxisConfig.min = min
        xAxisConfig.tickInterval = (max - min) / 10
        this.update({ xAxis: xAxisConfig })
      }
    }
  },
  exporting: { enabled: false },
  reflow: true,
  credits: { enabled: false },
  xAxis: {
    title: { text: '频率', style: { color: '#aeadad' } },
    labels: {
      style: { color: '#aeadad' }
    },
    tickAmount: 11,
    lineColor: '#aeadad',
    lineWidth: 0
  },
  yAxis: {
    title: { text: '幅度(dBuV/m)', style: { color: '#aeadad' } },
    min: spectrum.refLevel - 100,
    max: spectrum.refLevel,
    gridLineColor: 'rgba(1, 84, 120, 0.8)',
    gridLineDashStyle: 'solid',
    gridLineWidth: 0.5,
    lineColor: 'rgba(1, 84, 120, 1)',
    tickAmount: 11,
    labels: { style: { color: '#aeadad' } }
  },
  title: { enabled: false, text: '' },
  boost: { useGPUTranslations: true },
  legend: {
    enabled: false
    // itemStyle: { color: '#fff' },
    // itemHoverStyle: { color: '#f3f3f3' },
    // navigation: { enabled: false },
    // padding: 0,
    // margin: 2
  },
  series: [
    {
      id: 'current',
      name: '实时',
      color: '#ffff00',
      marker: { enabled: false },
      animation: false,
      enableMouseTracking: false,
      type: 'line',
      data: [],
      lineWidth: 0.5,
      boostThreshold: 100000
    },
    {
      id: 'average',
      name: '平均',
      color: '#f56c6c',
      marker: { enabled: false },
      animation: false,
      enableMouseTracking: false,
      type: 'line',
      data: [],
      lineWidth: 0.5
    },
    {
      id: 'max',
      name: '最大',
      color: '#67c23a',
      marker: { enabled: false },
      animation: false,
      enableMouseTracking: false,
      type: 'line',
      data: [],
      lineWidth: 0.5
    },
    {
      id: 'min',
      name: '最小',
      color: '#409eff',
      marker: { enabled: false },
      animation: false,
      enableMouseTracking: false,
      type: 'line',
      data: [],
      lineWidth: 0.5
    },
    {
      id: 'limit',
      name: '门限',
      color: '#fff',
      marker: { enabled: false },
      animation: false,
      enableMouseTracking: false,
      type: 'line',
      data: [],
      lineWidth: 0.5
    }
  ]
}
